<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>016_封装防抖方法</title>
</head>
<body>
  
</body>
<script>
  function debounce (fn) {
    var timerId;
    function helper () {
      if (timerId) {
        clearTimeout(timerId);
        timerId = null;
      }
      timerId = setTimeout(function (){
        fn();
      }, 500);
    }
    return helper;
  }

  function notifyChange() {
    console.log('浏览器的窗口改变了');

  }
window.addEventListener('resize', debounce(notifyChange));
</script>
</html>